﻿
using hentity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace hutil {
    /**
   *┌────────────────────────────────────────────────┐
   *│　描    述：MatrixesUtil                                                    
   *│　作    者：sgj                                              
   *│　版    本：1.0                                              
   *│　创建时间：2021/11/10 14:17:52                        
   *└────────────────────────────────────────────────┘
   **/
    public class MatrixesUtil {
        // 计算 |p1 p2| X |p1 p|
        static double GetCross(Point p1,Point p2  ,Point p ) {
            return (p2.X - p1.X) * (p.Y - p1.Y) - (p.X - p1.X) * (p2.Y - p1.Y);
        }
        //判断点p是否在p1p2p3p4的正方形内
      public static  bool isPointInMatrix(Point p1 , Point p2, Point p3, Point p4, Point p) {
            bool isPointIn = GetCross(p1 ,p2 ,p) * GetCross(p3 ,p4 ,p) > 0 && GetCross(p2 ,p3 ,p) * GetCross(p4 ,p1 ,p) > 0;
            return isPointIn;
      }

        public static bool isPointInMatrix(double x1 ,double y1 ,double x2 ,double y2 ,double x ,double y) {
            Point p1 = new Point(x1 ,y1);
            Point p2 = new Point(x1 ,y2);
            Point p3 = new Point(x2 ,y2);
            Point p4 = new Point(x2 ,y1);
            Point p = new Point(x ,y);
   
            return isPointInMatrix( p1 , p2 , p3 , p4 , p);
        }
    }
}
